﻿#include "ListDialogChoose.h"
#include "ui_ListDialogChoose.h"
#include "GUIWidget/WidgetBrowserTable.h"
#include "GUIWidget/TreeItemTypes.h"
#include "GUIWidget/BrowserTableHandlerMaterialFluid.h"
#include "GUIWidget/BrowserTableHandlerSpectraModalDensity.h"
#include "GUIWidget/BrowserTableHandlerSpectraWavenumber.h"
#include "GUIWidget/BrowserTableHandlerSpectraDampingLossFactor.h"
#include "GUIWidget/BrowserTableHandlerSpectraAbsorptionCoefficient.h"
#include "GUIWidget/BrowserTableHandlerSpectraCouplingLossFactor.h"
#include "GUIWidget/BrowserTableHandlerSpectraAcceleration.h"
#include "GUIWidget/BrowserTableHandlerSpectraAngularVelocity.h"
#include "GUIWidget/BrowserTableHandlerSpectraEnergy.h"
#include "GUIWidget/BrowserTableHandlerSpectraForce.h"
#include "GUIWidget/BrowserTableHandlerSpectraInsertionLoss.h"
#include "GUIWidget/BrowserTableHandlerSpectraMoment.h"
#include "GUIWidget/BrowserTableHandlerSpectraPower.h"
#include "GUIWidget/BrowserTableHandlerSpectraPressure.h"
#include "GUIWidget/BrowserTableHandlerSpectraShearModulus.h"
#include "GUIWidget/BrowserTableHandlerSpectraTransmissionLoss.h"
#include "GUIWidget/BrowserTableHandlerSpectraVelocity.h"
#include "GUIWidget/BrowserTableHandlerMaterialIsosolid.h"
#include "GUIWidget/BrowserTableHandlerMaterialVisESolid.h"
#include "GUIWidget/BrowserTableHandlerMaterialFoam.h"
#include "GUIWidget/BrowserTableHandlerMaterialFiber.h"
#include "GUIWidget/BrowserTableHandlerMaterialFE.h"
#include "GUIWidget/BrowserTableHandlerPhysicsBeam.h"
#include "GUIWidget/BrowserTableHandlerPhysicsUniform.h"
#include "GUIWidget/BrowserTableHandlerPhysicsGeneralLaminate.h"
#include "GUIWidget/BrowserTableHandlerPhysicsRibbed.h"
#include "GUIWidget/BrowserTableHandlerNCTLayUp.h"
#include "GUIWidget/BrowserTableHandlerNCTUserDefined.h"
#include "GUIWidget/BrowserTableHandlerNCTMultiple.h"
#include <QGridLayout>
#include <QHBoxLayout>
namespace GUI
{
    ListDialogChoose::ListDialogChoose(const QString &actionName, QWidget* parent /*= nullptr*/)
        :FITKDialog(parent)
    {
        _ui = new Ui::ListDialogChoose;
        _ui->setupUi(this);

        // 去掉帮助按钮
        setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

        _tableWidget = new WidgetBrowserTable(this);
        //添加窗体
        QHBoxLayout *hLay = new QHBoxLayout();
        hLay->addWidget(_ui->label);
        hLay->addWidget(_ui->comboBox);
        QSpacerItem * sparcer_item = new QSpacerItem(160, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
        hLay->addItem(sparcer_item);
        QGridLayout * lay = new QGridLayout();
        lay->addLayout(hLay,0,0);
        lay->addWidget(_tableWidget,1,0);
        setLayout(lay);
        this->init(actionName);
    }

    ListDialogChoose::~ListDialogChoose()
    {
        if (_ui)delete _ui;
    }

    void ListDialogChoose::init(const QString &actionName)
    {
        QStringList items;
        //对话框标题
        QString titleName = "";
        if (actionName == "actionMaterialList"){
            _ui->comboBox->addItem("Fluids", GUI::PTMatFluids);
            _ui->comboBox->addItem("Isotropic Solids", GUI::PTMatIsoSolid);
            _ui->comboBox->addItem("Visco-Elastic Solids", GUI::PTMatViscoElastic);
            _ui->comboBox->addItem("Foams", GUI::PTMatFoam);
            _ui->comboBox->addItem("Fibers", GUI::PTMatFiber);
            _ui->comboBox->addItem("FE Material Cards [MID]", GUI::PTMatFEMaterial);
            titleName = tr("Material List");
        }
        else if (actionName == "actionNCTList"){
            _ui->comboBox->addItem("Treatment Lay-Up", GUI::PTNCTLayUp);
            _ui->comboBox->addItem("User Define Treatment", GUI::PTNCTUserDef);
            _ui->comboBox->addItem("Multiple Noise Control Treatment", GUI::PTNCTMultiple);
            titleName = tr("Noise Control Treatment List");
        }
        else if (actionName == "actionPropertyList"){
            _ui->comboBox->addItem("Beams", GUI::PTPPBeam);
            _ui->comboBox->addItem("Uniform", GUI::PTPPShellUniform);
            _ui->comboBox->addItem("General Laminate", GUI::PTPPShellGeneralLaminate);
            _ui->comboBox->addItem("Ribbed", GUI::PTPPShellRibbed);
            titleName = tr("Physical Properties List");
        }
        else if (actionName == "actionSpectraList"){
            titleName = tr("Spectra List");
        }
        else if (actionName == "actionLoadListView"){
            titleName = tr("Load List");
        }
        setWindowTitle(titleName);

    }

    void ListDialogChoose::on_comboBox_currentTextChanged(const QString &arg) 
    {
        GUI::BrowserTableAbstractHandler* handler = nullptr;
        GUI::PropTreeItemsType itemType = (GUI::PropTreeItemsType)_ui->comboBox->currentData().toInt();
        switch (itemType)
        {
            //材料
        case GUI::PTMatFluids:
            handler = new GUI::BrowserTableHandlerMaterialFluid(_tableWidget); break;
        case GUI::PTMatIsoSolid:
            handler = new GUI::BrowserTableHandlerMaterialIsoSolid(_tableWidget); break;
        case GUI::PTMatViscoElastic:
            handler = new GUI::BrowserTableHandlerMaterialVisESolid(_tableWidget); break;
        case GUI::PTMatFoam:
            handler = new GUI::BrowserTableHandlerMaterialFoam(_tableWidget); break;
        case GUI::PTMatFiber:
            handler = new GUI::BrowserTableHandlerMaterialFiber(_tableWidget); break;
        case GUI::PTMatFEMaterial:
            handler = new GUI::BrowserTableHandlerMaterialFE(_tableWidget); break;

            //频谱
        case GUI::PTSModalDensity:
            handler = new GUI::BrowserTableHandlerSpectraModalDensity(_tableWidget); break;
        case GUI::PTSWavenumber:
            handler = new GUI::BrowserTableHandlerSpectraWavenumber(_tableWidget); break;
        case GUI::PTSDamping:
            handler = new GUI::BrowserTableHandlerSpectraDampingLossFactor(_tableWidget); break;
        case GUI::PTSAbsorption:
            handler = new GUI::BrowserTableHandlerSpectraAbsorptionCoefficient(_tableWidget); break;
        case GUI::PTSCoupling:
            handler = new GUI::BrowserTableHandlerSpectraCouplingLossFactor(_tableWidget); break;
        case GUI::PTSAcceleration:
            handler = new GUI::BrowserTableHandlerSpectraAcceleration(_tableWidget); break;
        case GUI::PTSAnlrVelocity:
            handler = new GUI::BrowserTableHandlerSpectraAngularVelocity(_tableWidget); break;
        case GUI::PTSEnergy:
            handler = new GUI::BrowserTableHandlerSpectraEnergy(_tableWidget); break;
        case GUI::PTSForce:
            handler = new GUI::BrowserTableHandlerSpectraForce(_tableWidget); break;
        case GUI::PTSInsertionLoss:
            handler = new GUI::BrowserTableHandlerSpectraInsertionLoss(_tableWidget); break;
        case GUI::PTSMoment:
            handler = new GUI::BrowserTableHandlerSpectraMoment(_tableWidget); break;
        case GUI::PTSPower:
            handler = new GUI::BrowserTableHandlerSpectraPower(_tableWidget); break;
        case GUI::PTSPressure:
            handler = new GUI::BrowserTableHandlerSpectraPressure(_tableWidget); break;
        case GUI::PTSShearModulus:
            handler = new GUI::BrowserTableHandlerSpectraShearModulus(_tableWidget); break;
        case GUI::PTSTransmissionLoss:
            handler = new GUI::BrowserTableHandlerSpectraTransmissionLoss(_tableWidget); break;
        case GUI::PTSVelocity:
            handler = new GUI::BrowserTableHandlerSpectraVelocity(_tableWidget); break;

            //物理属性
        case GUI::PTPPBeam:
            handler = new GUI::BrowserTableHandlerPhysicsBeam(_tableWidget); break;
        case GUI::PTPPShellUniform:
            handler = new GUI::BrowserTableHandlerPhysicsUniform(_tableWidget); break;
        case GUI::PTPPShellGeneralLaminate:
            handler = new GUI::BrowserTableHandlerPhysicsGeneralLaminate(_tableWidget); break;
        case GUI::PTPPShellRibbed:
            handler = new GUI::BrowserTableHandlerPhysicsRibbed(_tableWidget); break;

            //声学包
        case GUI::PTNCTLayUp:
            handler = new GUI::BrowserTableHandlerNCTLayUp(_tableWidget); break;
        case GUI::PTNCTUserDef:
            handler = new GUI::BrowserTableHandlerNCTUserDefined(_tableWidget); break;
        case GUI::PTNCTMultiple:
            handler = new GUI::BrowserTableHandlerNCTMultiple(_tableWidget); break;
        default: break;
        }

        if (handler)
            _tableWidget->update(handler);
    }
}